package com.ny.view;

import com.ny.Dao.impl.StudentServiceImpl;
import com.ny.entity.Student;
import com.ny.service.StudentService;

import java.sql.SQLException;
import java.util.Scanner;
    //调用业务层的方法
    public class ViewMain {
        private static StudentService service ;
        public static void main(String[] args) throws SQLException, ClassNotFoundException {
            service = new StudentServiceImpl();
            Student student = new Student();
            boolean flag = true;
            while (flag){
                System.out.println("欢迎来到校园商品售卖管理系统");
                System.out.println("请选择你的操作");
                System.out.println("1.用户登录");
                System.out.println("2.管理员登录");
                System.out.println("3.注册账号");
                System.out.println("0.退出系统");
                Scanner scanner  = new Scanner(System.in);
                int i = scanner.nextInt();
                switch (i){
                    case 1:
                        System.out.println("用户登录");
                        System.out.println("请输入用户名");
                        String studentName = scanner.next();
                        System.out.println("请输入密码");
                        String studentPassword = scanner.next();
                        // 调用业务层的登录功能：
                        student = service.login(studentName, studentPassword);
                        if(student!=null){
                            System.out.println("登录成功");
                            IndexView indexView = new IndexView();
                            indexView.indexView(student);
                        }
                        else {
                            System.out.println("登录失败");
                        }
                        break;
                    case 2:
                        System.out.println("管理员登录");
                        break;
                    case 3:
                        System.out.println("请输入用户名");
                        student.setStudentName(scanner.next());
                        System.out.println("请输入密码");
                        student.setStudentPassword(scanner.next());
                        System.out.println("请输入手机号");
                        student.setStudentPhone(scanner.next());
                        int add = service.add(student);
                        break;
                    case 4:
                        flag = false;
                        break;
                }
            }



        }



    }

